#include "Factory.h"
#include "SFML/Graphics.hpp"
#include <map>

const int texturesNum = 7;
char *textures [] =
{ 
	"carsprite.png",
	"deadbody.png",
	"deadbody1.png",
	"deadbody2.png",
	"deadbody3.png",
	"deadbody4.png",
	"deadbody5.png",
	"bullet.png",
};

using namespace std;
map<string, sf::Texture*> textureLib;

int main()
{
	sf::VideoMode videoMode(1024, 768);
	sf::RenderWindow win(videoMode, "SEATBLAST");

	for (int i = 0; i < texturesNum; i++)
	{
		sf::Texture *t = new sf::Texture;
		t->loadFromFile( textures[i] );
		textureLib[textures[i]] = t;
	}

	textureLib["carsprite.png"];

	sf::Texture textureCar;
	textureCar.loadFromFile("images/carSprite.png");
	sf::Texture textureCarDead;
	textureCarDead.loadFromFile("images/carSprite_dead.png");
	sf::Texture textureBody;
	textureBody.loadFromFile("images/deadbody.png");
	sf::Texture textureChar;
	textureChar.loadFromFile("images/character.png");

	Body *body = new Body(textureBody);
	body->sprite.setOrigin(32, 32);

	Car *player = new Car(textureCar, textureCarDead, body);
	player->sprite.setOrigin(128,128);
	player->sprite.setPosition( win.getSize().x * 0.5f, win.getSize().y * 0.5f );

	PlayerChar *playerChar = new PlayerChar(textureChar, textureBody, player);
	playerChar->sprite.setOrigin(32, 32);
	playerChar->sprite.setPosition(64,64);

	sf::Clock time;

	while (win.isOpen())
	{
		float deltaTime = time.getElapsedTime().asSeconds();
		time.restart();

		sf::Event e;
		while (win.pollEvent(e))
		{
			Factory::AlertObjects(e);

			if ((e.type == sf::Event::KeyReleased && e.key.code == sf::Keyboard::Escape) || e.type == sf::Event::Closed)
			{
				win.close();
			}
		}

		Factory::UpdateAll(deltaTime);

		win.clear( sf::Color(20,20,20,255) );
		Factory::RenderAll(win);
		win.display();
	}
}